package chian.mobile.service.impl;

import chian.mobile.service.MobileAIService;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;

/**
 * @author cc
 * @version V1.0
 * @date 2025-20 21:00
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class MobileAIServiceImpl implements MobileAIService {

    @Resource
    private MobileAIService mobileAIService;
    private final ChatClient chatClient;


    @Override
    public Flux<String> flux(String question, String sessionId) {
        return chatClient.prompt()
                .user(question)
                .advisors(advisor -> advisor
                                .param(AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY,sessionId)
                        )
                .stream()
                .content()
                .concatWith(Flux.just("[END]"));
    }
}
